/*
 * ExtendedChatMessage.h
 */

#ifndef EXTENDEDCHATMESSAGE_H_
#define EXTENDEDCHATMESSAGE_H_

#include "ariba/ariba.h"
#include <boost/date_time/posix_time/posix_time.hpp>
using boost::posix_time::ptime;

#include <boost/property_tree/detail/xml_parser_error.hpp>
#include <boost/property_tree/exceptions.hpp>

using namespace std;
using boost::property_tree::ptree;

using_serialization
;

class ExtendedChatMessage: public ariba::Message
{
VSERIALIZEABLE
	;
public:
	/// Required for de-serialization
	ExtendedChatMessage();

	virtual ~ExtendedChatMessage();

	uint32_t messageId;
	ptime timeStamp;
	string text;

	/// not serialized, for XML use only
	string from;
	string to;

	string getXml(bool isEcho = false);

	void parseXml(ptree& pt);
};

sznBeginDefault(ExtendedChatMessage, X)
{
	X && messageId;
	
	if (X.isSerializer())
	{
		string ts = boost::posix_time::to_iso_string(timeStamp);
		X && T(ts);
	}
	else
	{
		string ts;
		X && T(ts);
		timeStamp = boost::posix_time::from_iso_string(ts);
	}
	
	X && T(text);
}sznEnd();

#endif /* EXTENDEDCHATMESSAGE_H_ */
